<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>注册页面</title>
		<link rel="stylesheet" href="css/index.css" />
		<script src="js/vue.js"></script>
		<script src="js/elementui.js"></script>
		<script src="js/axios.js"></script>
		<script src="js/common.js"></script>
	</head>
	<style>
		body{
		    background-image: url(img/yi1.jpg);
		}
		.dl{
			margin-top: 300px;
		}
		.el-form-item__label{
			color: black;
		}
	</style>
	<body>
		<div id="app">
			<div id="app">
				<center>
					<div style="width: 500px;" class="dl">
						<h2 style="text-align: center;">
							注册
						</h2>
						<el-form ref="form" :model="form" label-width="80px">
							<el-form-item label="用户名">
								<el-input v-model="form.uname"></el-input>
							</el-form-item>
							<el-form-item label="密码">
								<el-input type="password" v-model="form.upwd"></el-input>
							</el-form-item>
							<el-form-item>
								<el-button type="primary" @click="sign">注册</el-button>
								<el-button type="primary" @click="res">返回</el-button>
							</el-form-item>
						</el-form>
					</div>
				</center>
			</div>
		</div>
	</body>
	<script>
		new Vue({
			el:'#app',
			data:{
				form: {
					uname: '',
					upwd: ''
				}
			},
			methods:{
				sign(){
					var that=this;
					if(this.form.uname!=null||this.form.upwd!=null){
					axios.post(API+'insertUser?name='+this.form.uname+"&pwd="+this.form.upwd)
					.then(function(res) {
						console.log(res);
						if (res.data.data.i>0) {
								alert("注册成功");
								that.form = {
									uname: '',
									upwd: ''
								}
								that.res();
							}
						else {
								alert('注册失败');
							}
					});
					}else{
						alert('注册失败，请检查用户名和密码');
					}
				},
				res(){
					window.location.href="login.html";
				}
			}
		})
	</script>
</html>